﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using Microsoft.Reporting.WebForms;
using System.Xml.Linq;
using Viewer.Base.Config;
using System.Data;

namespace Viewer.NhanSu.Reporting
{
    public partial class RptChatLuongCanBo : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                LoadDataComboboxLoai();
            }
        }
        protected void MasterScriptManager_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)
        {
            // TODO: see if this is ever invoked
        }

        protected void Page_Init(object sender, EventArgs e)
        {
            var MasterScriptManager = (ScriptManager)this.FindControl("MasterScriptManager");
            MasterScriptManager.EnablePartialRendering = false;

        }
        [DirectMethod]
        public void btnGenerate_Click()
        {
            string titleWindow = string.Empty;
            string reportPath = string.Empty;
            if (string.IsNullOrEmpty(txtToChuc.Text))
            {
                hdTochucID.Text = string.Empty;
            }

            if (hdReportType.Value.Equals("0"))
            {
                reportPath = ViewerConstant.NameReport.NSTrinhDoChuyenMon;               
            }
            else if (hdReportType.Value.Equals("1"))
            {
                reportPath = ViewerConstant.NameReport.NSBangCap;
            }
            else if (hdReportType.Value.Equals("2"))
            {
                reportPath = ViewerConstant.NameReport.NSLiLuanChinhTri;
            }
            else if (hdReportType.Value.Equals("3"))
            {
                reportPath = ViewerConstant.NameReport.NSQuanLiNhaNuoc;
            }
            else if (hdReportType.Value.Equals("4"))
            {
                reportPath = ViewerConstant.NameReport.NSTrinhDoNgoaiNgu;
            }
            else if (hdReportType.Value.Equals("5"))
            {
                reportPath = ViewerConstant.NameReport.NSTinHoc;
            }
            string strParameter = string.Format("{0},{1},{2},{3}", reportPath, txtToChuc.Text, hdTochucID.Value.ToString(), cbbYear.Text);
            UCReporting.LoadReport(strParameter);

            PnlSearch.Hidden = false;
        }
        /// <summary>
        /// Reset button click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        [DirectMethod]
        public void btnReset_Click()
        {
            txtToChuc.Text = string.Empty;
            hdTochucID.Text = string.Empty;
            cbbYear.Clear();
            //Load lại data cho tree          
            PnlSearch.Hidden = false;
        }
        [DirectMethod]
        public void ShowPopUp()
        {
            UcToChuc.ShowLookUp_ToChuc("", true, "");
        }
        private void LoadDataComboboxLoai()
        {
            string xmlFile = Server.MapPath(ViewerConstant.FILEPATH_Report_XML);

            DataSet ds1 = new DataSet();
            ds1.ReadXml(xmlFile);
            storeNam.DataSource = ds1.Tables["Nam"];
            storeNam.DataBind();
        }
        [DirectMethod]
        public void SetHidden(bool check)
        {
            PnlSearch.Hidden = check;
            btnReset_Click();
        }
    }
}